package com.leetcode.p400;

import com.bean.TreeNode;
import com.utils.TreeUtils;

import java.util.HashMap;

public class Test437_2 {

    public int pathSum(TreeNode root, int targetSum) {
        HashMap<Integer, Integer> map = new HashMap<>();
        return dfs(root, targetSum, map, 0);
    }

    private int dfs(TreeNode root, int targetSum, HashMap<Integer, Integer> map, long curr) {
        if (root == null) {
            return 0;
        }

        int ret = 0;

        curr = curr + root.val;
        if (targetSum == curr) {
            ret++;
        }


        return ret;
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeUtils.buildTree("10,5,-3,3,2,null,11,3,-2,null,1");
        TreeUtils.showTree(treeNode);
        Test437_2 test = new Test437_2();
        System.out.println(test.pathSum(treeNode, 8));
    }
}
